use rand::Rng;
use std::cmp::Ordering;
use std::io;
use std::{thread, time};
use std::fmt::Debug;
use std::net::{IpAddr, Ipv4Addr};


#[derive(Debug)]
enum UsState {
    Alabama,
    Alaska,
    // --snip--
}

// 硬币类型
enum Coin {
    Penny,
    Nickel,
    Dime,
    Quarter(UsState),
}

pub fn ifLet() {
    println!("#################################");
    println!("##      if let 简洁控制流          ");
    println!("#################################");
    println!("ifLet");

    let config_max = Some(3u8);
    match config_max {
        Some(max) => println!("The maximum is configured to be {}", max),
        _ => (),
    }
    // 等价于 ==>
    let config_max= Some(3u8);
    if let Some(max) = config_max {
        println!("The maximum is configured to be {}", max);
    }

    let mut count1 = 0;
    let coin = Coin::Dime;
    match coin {
        Coin::Quarter(state) => println!("State quarter from {:?}!", state),
        _ => count1 += 1,
    }
    println!("State quarter count1 {}", count1);
    // // 等价于 ==>
    let mut count2 = 0;
    let coin2 = Coin::Dime;
    if let  Coin::Quarter(state) = coin2 {
        println!("State quarter from {:?}!", state);
    } else {
        count2 += 1;
    }
    println!("State quarter count2 {}", count2);
}